// 对队列中的任务进行封装
#pragma once
#include <iostream>
#include <functional>
#include <string>

class Task
{
private:
    typedef std::function<int(int, int, char)> func_t;

public:
    Task(int x, int y, char op, func_t func)
        : _x(x), _y(y), _op(op), _func_t(func)
    {
    }
    Task()
    {
        
    }

    std::string operator()()
    {
        int res = _func_t(_x, _y, _op);
        char buffer[1024];
        snprintf(buffer, sizeof buffer, "%d %c %d = %d", _x, _op, _y, res);
        return buffer;
    }

    std::string toTaskName()
    {
        char buffer[1024];
        snprintf(buffer, sizeof(buffer), "%d %c %d = ?", _x, _op, _y);
        return buffer;
    }

    ~Task() {}

private:
    func_t _func_t; // 调用的方法
    int _x;
    int _y;
    char _op; // 选择的运算符
};

static std::string opArr = "+-*/%";

int mymath(int x, int y, char op)
{
    int result = 0;
    switch (op)
    {
    case '+':
        result = x + y;
        break;
    case '-':
        result = x - y;
        break;
    case '*':
        result = x * y;
        break;
    case '/':
    {

        if (y == 0)
        {
            std::cout << "div zero error!" << std::endl;
            return -1;
        }
        else
        {
            result = x / y;
        }
    }
    break;
    case '%':
    {

        if (y == 0)
        {
            std::cout << "mod zero error!" << std::endl;
            return -1;
        }
        else
        {
            result = x % y;
        }
    }
    break;
    default:
        // do nothing
        break;
    }

    return result;
}